#include"common.h"
#include"Socket.h"
int main()
{
    Socket* cli_sock=new Socket("127.0.0.1",8080);
    cli_sock->Connect();
    while(true)
    {
        char buff[BUFFER_NUM];
        bzero(buff,sizeof(buff));
        std::string line;
        getline(std::cin,line);
        for(int i=0;i<line.size();i++)
        {
            buff[i]=line[i];
        }
        int cli_fd=cli_sock->GetFd();
        int write_bytes=write(cli_fd,buff,strlen(buff));
        //myassert退出会执行~socket close(cli_fd)
        myAssert(write_bytes!=-1,"client write error,cli_fd already closed");
        bzero(buff,sizeof(buff));
        int read_bytes=read(cli_fd,buff,sizeof(buff));
        if(read_bytes>0)
        {
            printf("the messager from server echo %s\n",buff);
        }
        else if(read_bytes==0)
        {
            printf("error! server is disconnected");
            break;
        }
        else
        {
            myAssert(false,"client read error!");
            break;
        }
    }
    return 0;
}